<template>
  <div class="app-container">
    <el-form :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      class="form-search"
      label-width="80px">

      <el-form-item label="付款状态"
        prop="payStatus">
        <el-select v-model="queryParams.payStatus"
          placeholder="请选择付款状态"
          clearable
          style="width: 240px">
          <el-option key="1"
            label="已付款"
            value="0" />
          <el-option key="0"
            label="未付款"
            value="0" />
        </el-select>
      </el-form-item>
      <el-form-item label="处理状态"
        prop="processStatus">
        <el-select v-model="queryParams.processStatus"
          placeholder="请选择处理状态"
          clearable
          style="width: 240px">
          <el-option key="1"
            label="已处理"
            value="0" />
          <el-option key="0"
            label="未处理"
            value="0" />
        </el-select>
      </el-form-item>
      <el-form-item label="手机号码"
        prop="phone">
        <el-input v-model="queryParams.phone"
          placeholder="请输入手机号码"
          clearable
          style="width: 240px"
          maxlength="50"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="姓氏"
        prop="firstName">
        <el-input v-model="queryParams.firstName"
          placeholder="请输入姓氏"
          clearable
          style="width: 240px"
          maxlength="50"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="性别"
        prop="sex">
        <el-select v-model="queryParams.sex"
          placeholder="请选择性别"
          clearable
          style="width: 240px">
          <el-option key="1"
            label="男"
            value="男" />
          <el-option key="0"
            label="女"
            value="女" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery">搜 索</el-button>
        <el-button icon="el-icon-refresh"
          size="mini"
          @click="resetQuery">重 置</el-button>
      </el-form-item>
    </el-form>

    <div class="section-box">

      <el-table v-loading="loading"
        :data="dataList">
        <el-table-column label="预约ID"
          align="center"
          prop="id"
          min-width="60" />
        <el-table-column label="姓名"
          align="center"
          prop="firstName"
          :show-overflow-tooltip="true"
          min-width="160" />
        <el-table-column label="性别"
          align="center"
          prop="sex"
          min-width="120">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_user_sex"
              :value="scope.row.sex" />
          </template>
        </el-table-column>
        <el-table-column label="付款状态"
          align="center"
          prop="sex"
          min-width="120">
          <template slot-scope="scope">
            <span>{{scope.row.payStatus == '1'? '已付': '未付'}}</span>
          </template>
        </el-table-column>
        <el-table-column label="电话"
          align="center"
          prop="phone"
          :show-overflow-tooltip="true"
          min-width="160" />

        <el-table-column label="客户留言"
          align="center"
          prop="msg"
          :show-overflow-tooltip="true"
          min-width="160" />
        <el-table-column label="处理状态"
          align="center"
          prop="processStatus"
          min-width="120">
          <template slot-scope="scope">
            <span>{{scope.row.processStatus == '1'? '已处理': '未处理'}}</span>
          </template>
        </el-table-column>
        <el-table-column label="处理时间"
          align="center"
          prop="processTime"
          min-width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.processTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="处理说明"
          align="center"
          prop="processRemark"
          :show-overflow-tooltip="true"
          min-width="160" />
        <el-table-column label="处理人"
          align="center"
          prop="processName"
          :show-overflow-tooltip="true"
          min-width="120" />
        <el-table-column label="占卜问题"
          align="center"
          prop="categoryName"
          :show-overflow-tooltip="true"
          min-width="160" />
        <el-table-column label="所得卦"
          align="center"
          prop="guaName"
          :show-overflow-tooltip="true"
          min-width="160" />

        <el-table-column label="创建人"
          align="center"
          prop="createBy"
          min-width="140"
          show-overflow-tooltip />
        <el-table-column label="创建时间"
          align="center"
          prop="createTime"
          min-width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="更新人"
          align="center"
          prop="updateBy"
          min-width="140"
          show-overflow-tooltip />
        <el-table-column label="更新时间"
          align="center"
          prop="updateTime"
          min-width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注"
          align="center"
          prop="remark"
          :show-overflow-tooltip="true"
          min-width="160" />

        <el-table-column label="操作"
          align="center"
          class-name="small-padding fixed-width"
          fixed="right"
          min-width="100">
          <template slot-scope="scope">
            <el-button size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>

    <!-- 添加或修改角色配置对话框 -->
    <el-dialog :title="title"
      :visible.sync="open"
      width="500px"
      append-to-body>
      <el-form ref="form"
        :model="form"
        :rules="rules"
        label-width="100px">

        <el-form-item label="购买状态"
          prop="payStatus">
          <el-select v-model="form.payStatus"
            placeholder="请选择购买状态"
            clearable
            style="width: 100%">
            <el-option key="1"
              label="已购买"
              value="1" />
            <el-option key="0"
              label="未购买"
              value="0" />
          </el-select>
        </el-form-item>
        <el-form-item label="处理状态"
          prop="processStatus">
          <el-select v-model="form.processStatus"
            placeholder="请选择处理状态"
            clearable
            style="width: 100%">
            <el-option key="1"
              label="已处理"
              value="1" />
            <el-option key="0"
              label="未处理"
              value="0" />
          </el-select>
        </el-form-item>
        <el-form-item label="处理时间"
          prop="processTime">
          <el-date-picker v-model="form.processTime"
            type="date"
            placeholder="请选择处理时间"
            clearable
            style="width: 100%"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理人"
          prop="processName">
          <el-input v-model.trim="form.processName"
            maxlength="50"
            placeholder="请输入处理人">
          </el-input>
        </el-form-item>
        <el-form-item label="处理备注"
          prop="processRemark"
          style="width: 100%;">
          <el-input type="textarea"
            v-model="form.processRemark"
            style="width: 100%;"
            maxlength="2000"
            placeholder="请输入处理备注">
          </el-input>
        </el-form-item>
        <el-form-item label="备注"
          prop="remark"
          style="width: 100%;">
          <el-input type="textarea"
            v-model="form.remark"
            style="width: 100%;"
            maxlength="2000"
            placeholder="请输入备注">
          </el-input>
        </el-form-item>

      </el-form>
      <div slot="footer"
        class="dialog-footer">
        <el-button type="primary"
          @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  getYuyueList,
  yuyueDetail,
  updateYuyue
} from "@/api/divination/decipherDivination.js";
import { onInput } from '@/utils/util.js'

export default {
  name: "DecipherDivination",
  dicts: ['sys_user_sex'],
  data () {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        payStatus: null,
        processStatus: null,
        phone: null,
        firstName: null,
        sex: null,
      },
      // 数据列表
      dataList: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created () {
    this.getList();
  },
  methods: {
    onInput,
    /** 查询列表 */
    getList () {
      this.loading = true;
      getYuyueList(this.queryParams).then(
        (response) => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        payStatus: null,
        processStatus: null,
        processTime: null,
        processRemark: null,
        processName: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 新增按钮操作 */
    // handleAdd () {
    //   this.reset();
    //   this.open = true;
    //   this.title = '新增名嘴资料';
    // },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.reset();
      this.form = JSON.parse(JSON.stringify(row));
      this.open = true;
      this.title = '修改解卦预约';
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          // if (this.form.shangId != undefined) {
          updateYuyue(this.form).then((response) => {
            this.$modal.msgSuccess('修改成功');
            this.open = false;
            this.getList();
          });
          // } else {
          //   addStarTalk(this.form).then((response) => {
          //     this.$modal.msgSuccess('新增成功');
          //     this.open = false;
          //     this.getList();
          //   });
          // }
        }
      });
    }
  },
};
</script>
